/***************************************************************************
 *  Filename: processgui.cpp
 *  Class: ProcessGUI
 *
 *  Copyright 2012  Xander van Kooten
 *  <xandervk@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *
 ****************************************************************************/

/*
 *
 * This file is part of Parsax-Remote-Controller.
 *
 *    Parsax-Remote-Controller is free software: you can redistribute it
 *    and/or modify it under the terms of the GNU General Public License
 *    as published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    Parsax-Remote-Controller is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Parsax-Remote-Controller.
 *    If not, see <http://www.gnu.org/licenses/>.
 */

#include "processgui.h"
#include "ui_processgui.h"

ProcessGUI::ProcessGUI(RemoteProcess *proc, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ProcessGUI)
{
    if(proc==0){
        process = new RemoteProcess(this);
    }else{
        process = proc;
    }
    ui->setupUi(this);

    setId("noid");
    setPc("nopc");
    setProgram("noprogram");
    setStatus("nostatus");
    connect(process, SIGNAL(cloReceived(int,QString)), SLOT(whenCloReceived(int,QString)));
}

ProcessGUI::~ProcessGUI()
{
    delete ui;
}

void ProcessGUI::setId(QString tid){
    process->setId(tid);
    emit infoUpdated();
}

void ProcessGUI::setPc(QString pc){
    process->setPc(pc);
    emit infoUpdated();
}

void ProcessGUI::setProgram(QString tprogram){
    process->setProgram(tprogram);
    ui->programEdit->setText(process->getProgram());
    emit infoUpdated();
}

void ProcessGUI::setParameters(QStringList tparameters){
    process->setParameters(tparameters);
    ui->paramEdit->setText(getParametersString());
    emit infoUpdated();
}

void ProcessGUI::setStatus(QString status){
    process->setStatus(status);
    emit infoUpdated();
}

QString ProcessGUI::getId(){
    return process->getId();
}

QString ProcessGUI::getPc(){
    return process->getPc();
}

QString ProcessGUI::getProgram(){
    return process->getProgram();
}

QString ProcessGUI::getParametersString(){
    return process->getParametersString();
}

QStringList ProcessGUI::getParameters(){
    return process->getParameters();
}

QString ProcessGUI::getStatus(){
    return process->getStatus();
}

void ProcessGUI::appendClo(QString lines){
    ui->cloEdit->append(lines);
}

void ProcessGUI::appendClE(QString lines){
    ui->cleEdit->append(lines);
}

RemoteProcess *ProcessGUI::getProcess(){
    return process;
}

void ProcessGUI::on_programEdit_editingFinished()
{
    setProgram(ui->programEdit->text());
}

void ProcessGUI::on_paramEdit_editingFinished()
{
    QStringList tmpList = ui->paramEdit->text().split(" ");
    setParameters(tmpList);
}

void ProcessGUI::whenCloReceived(int type, QString message){
    if(type==0){
        ui->cloEdit->append(message);
    }else{
        ui->cleEdit->append(message);
    }
}
